<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组移动函数</title>
</head>
<body>
    <script>
        let arr = [1,2,3,4,5];

        function move(arr,from,to){
            if(from < 0 || from >= arr.length || to < 0 || to >= arr.length){
                console.error("错误参数");
                return;
            };

            let newArr = [...arr];
            let value = newArr.splice(from,1);
            newArr.splice(to,0,...value);
            return newArr;
        };

        console.log(move(arr,3,1));
    </script>
</body>
</html>